package io.renren.modules.sys.utils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.renren.modules.sys.entity.PocketEntity;
import io.renren.modules.sys.entity.SysUserEntity;

import java.time.LocalDateTime;

/**
 * 首页查询utils
 *
 * @author Amadeus
 * @date 2020/12/24
 */
public class HomeUtils {

    private HomeUtils() {
        /* set something here */
    }

    /**
     * 构建最基本的查询条件
     *
     * @param wrapper 条件构造器
     */
    public static void buildSelectWrapper(SysUserEntity user, LambdaQueryWrapper<PocketEntity> wrapper) {

        wrapper.select(PocketEntity::getPayment)
                .eq(PocketEntity::getCreateBy, user.getUsername());
    }

    /**
     * 构建支出查询条件
     *
     * @param wrapper 条件构造器
     */
    public static void buildSumSelectWrapper(LambdaQueryWrapper<PocketEntity> wrapper) {
        //类型小于等于0的为支出数目
        wrapper.le(PocketEntity::getType, 0);
    }

    /**
     * 构建收入查询条件
     *
     * @param wrapper 条件构造器
     */
    public static void buildIncomeSelectWrapper(LambdaQueryWrapper<PocketEntity> wrapper) {
        //类型大于等于0的为支出数目
        wrapper.gt(PocketEntity::getType, 0);
    }

    /**
     * 构建上个月查询条件
     *
     * @param user    用户
     * @param wrapper 条件构造器
     */
    public static void buildLastMonthWrapper(SysUserEntity user, LambdaQueryWrapper<PocketEntity> wrapper, int year, int month) {
        buildSelectWrapper(user, wrapper);
        wrapper.le(PocketEntity::getPaydata, LocalDateTime.of(
                year, month + 1,
                1, 0, 0))
                .ge(PocketEntity::getPaydata, LocalDateTime.of(
                        year, month,
                        1, 0, 0));
    }
}
